package com.kuzlak.cms.model;


import com.kuzlak.cms.config.ConstantHeader;

public class SqlFeildModal {


    public static String getPicture(String key) {
        String path = ConstantHeader.getPathUrl();
        return "(SELECT IF(LOCATE('http',IMAGE_URL) > 0,URL,CONCAT('" + path + "',IMAGE_URL)) FROM  sys_pictures WHERE ID=x." + key + "  LIMIT 1)";
    }

    public static String getPictureMini(String key) {
        String path = ConstantHeader.getPathUrl();
        return "(SELECT IF(LOCATE('http',IMAGE_URL) > 0,IMAGE_URL,CONCAT('" + path + "',IMAGE_URL)) FROM  sys_pictures WHERE FIND_IN_SET(ID,x." + key + ")  LIMIT 1)";
    }

    public static String getPicturePublic(String key) {
        String path = ConstantHeader.getPathUrl();
        return "(SELECT IF(LOCATE('http',IMAGE_URL) > 0,URL,CONCAT('" + path + "',IMAGE_URL)) FROM  sys_pictures WHERE ID=" + key + "  LIMIT 1)";
    }

    public static String getPictures(String key) {
        String path = ConstantHeader.getPathUrl();
        return "(SELECT group_concat(IF(LOCATE('http',IMAGE_URL) > 0,IMAGE_URL,CONCAT('" + path + "',IMAGE_URL))) FROM  sys_pictures WHERE FIND_IN_SET(ID,x." + key + ")  LIMIT 1)";
    }


    public static String getAttrKeyValue(String attrKey, String value) {
        String sql = "(select NAME FROM  sys_dict_value where DICT_ID in (SELECT ID FROM  sys_dict where IS_KEY ='" + attrKey + "') and IS_VALUE=" + value + ")";
        return sql;
    }


    public static String getUserAvatar(String key) {
        String sql = "(SELECT AVATAR FROM  sys_users where  ID=" + key + " LIMIT 1)";
        return sql;
    }


    public static String getOtherTableColmuns(String tableName, String felid, String keyFelid) {
        return "(SELECT " + felid + " FROM " + tableName + " as t" + tableName + " where " + keyFelid + " LIMIT 1)";
    }





    public static String getOrganName(String key) {
        return "(SELECT ORGAN_SHORT_NAME FROM  sys_organ where  ID=" + key + " LIMIT 1)";
    }

    public static String organType(String key) {
        return "(SELECT TYPE FROM  sys_organ where  ID=" + key + " LIMIT 1)";
    }


    public static String addressName(String key) {
        return "(SELECT TITLE FROM  sys_address where  ID=" + key + " LIMIT 1)";
    }



    public static String getUserName(String key) {
        return "(SELECT NAME FROM  sys_users as tsys_users where  ID=" + key + " LIMIT 1)";
    }

    public static String getUserBySerachName(String key) {
        //  System.out.println("getUserBySerachName:"+key);
        return "(SELECT ID FROM  sys_users where NAME  LIKE '%" + key + "%')";
    }


}
